package com.qingke.serialization;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class StudentPersistent {

	public static void main(String[] args) {
		Student student = new Student("Qingke", "Male", 20);
		try {
			System.out.println("original: " + student);
			ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("student.output"));
			oos.writeObject(student);
			oos.flush();
			oos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			ObjectInputStream ois = new ObjectInputStream(new FileInputStream("student.output"));
			Object obj = ois.readObject();
			if (obj instanceof Student) {
				Student student2 = (Student)obj;
				System.out.println("persistent: " + student2);
			}
			ois.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

}
